package com.aaa.controller;

import com.aaa.entity.AApply_date;
import com.aaa.entity.F_orderp;
import com.aaa.entity.Inventory;
import com.aaa.service.impl.ApplydateServiceimpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("applydate")
public class Applydatecontroller {
    @Resource
    ApplydateServiceimpl applydateserviceimpl;

    @ResponseBody
    @RequestMapping("findpage")
    public Map<String, Object> userList(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<AApply_date> userList = applydateserviceimpl.findpage(pageSize, pageNum * pageSize);
        Integer TotalNum = applydateserviceimpl.findcount();

        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }

    @ResponseBody
    @RequestMapping("upd")
    public Integer upd(AApply_date aApply_date){
        return applydateserviceimpl.upd(aApply_date);
    }

    @ResponseBody
    @RequestMapping("select1")
    public List<AApply_date> select1(String name){
        System.out.println(name);
        return applydateserviceimpl.select1(name);
    }

    @RequestMapping("add")
    @ResponseBody
    public Integer add(AApply_date aApply_date){
        aApply_date.setDate(new Date());
        return applydateserviceimpl.add(aApply_date);
    }

    @ResponseBody
    @RequestMapping("select2")
    public Map<String, Object> select2(Integer pageSize, Integer pageNum){
        Map<String, Object> map = new HashMap<>();
        List<AApply_date> userList = applydateserviceimpl.select2(pageSize, pageNum * pageSize);
        Integer TotalNum = applydateserviceimpl.select2count();

        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }

    @ResponseBody
    @RequestMapping("select3")
    public List<AApply_date> select3(){
        return applydateserviceimpl.select3();
    }


    @ResponseBody
    @RequestMapping("select4")
    public Map<String, Object> select4(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<AApply_date> userList = applydateserviceimpl.select4(pageSize, pageNum * pageSize);
        Integer TotalNum = applydateserviceimpl.findcount1();

        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }

    @RequestMapping("putinstorage")
    @ResponseBody
    public Integer putinstorage(F_orderp f_orderp){
        Inventory inventory = new Inventory();
        inventory.setSurplus(f_orderp.getNum());
        inventory.setBook(f_orderp.getBook());
        return applydateserviceimpl.puinstorage(inventory);
    }
}
